#include "Scene_PCH.h"
#include "bObject.h"

/*--------------------------------------------------------------------------*/

bObject::bObject(btDiscreteDynamicsWorld* world) :
	m_discreteDynamicWorld(world)
{
	
}

/*--------------------------------------------------------------------------*/

bObject::~bObject()
{

}

/*--------------------------------------------------------------------------*/

void bObject::AddRigidBody(btCollisionShape* collisionshape, const bInitData& initdata )
{
	btDefaultMotionState* groundMotionState = new btDefaultMotionState(
														btTransform(btQuaternion(initdata.rotation.x, initdata.rotation.y, initdata.rotation.z, initdata.rotation.w), 
														btVector3(initdata.position.x, initdata.position.y, initdata.position.z)));

	btVector3 intertia;
	collisionshape->calculateLocalInertia(initdata.mass, intertia);

	btRigidBody::btRigidBodyConstructionInfo info(	initdata.mass, 
													groundMotionState, 
													collisionshape, 
													intertia);
	info.m_restitution		= initdata.restitution;
	info.m_friction			= initdata.friction;
	info.m_angularDamping	= initdata.angularDamping;
	info.m_linearDamping	= initdata.linearDamping;
	info.m_rollingFriction	= initdata.rollingFriction;

	m_rigidBody = new btRigidBody(info);

	m_discreteDynamicWorld->addRigidBody(m_rigidBody);
}

/*--------------------------------------------------------------------------*/

void bObject::RemoveRigidBody()
{
	m_discreteDynamicWorld->removeRigidBody(m_rigidBody);

	delete m_rigidBody->getMotionState();
	delete m_rigidBody;
}

/*--------------------------------------------------------------------------*/